//下载cheerio库，npm install cheerio
const cheerio = require("cheerio");
const http = require("http");
const fs = require("fs");
const path = require("path");

var filePath = path.join(__dirname,"/demo.html");
var fileContent = fs.readFileSync(filePath); //是个buffer类型的数据
fileContent = fileContent.toString("utf-8");

var $ = cheerio.load(fileContent);
$("ul li").each((i, el)=>{ 
    //获取ul下的li  each遍历
    console.log($(el).text()); //打印该节点下的文本内容
    console.log($(el).attr('id')); //获取节点id值
})